<template>
    <div v-if="returnReasonDialog.isVisible">
        <!--回退原因弹框-->
        <el-dialog :title="$t('common.returnReason')" :visible.sync="returnReasonDialog.isVisible" width="400px">
            <el-form ref="returnReasonDialog.form" :model="returnReasonDialog.form" :rules="returnReasonDialog.rules">
                <el-form-item prop="refuseRemark">
                    <el-input v-model="returnReasonDialog.form.refuseRemark" :maxlength="100" type="textarea"
                        :rows="4"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer">
                <el-button type="primary" @click="returnHandler">{{ $t('common.confirmOk') }}</el-button>
                <el-button type="cancel" @click="cancel">{{ $t('common.cancel') }}</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
export default {
    data() {
        return {
            returnReasonDialog: {
                isVisible: false,
                form: {
                    refuseRemark: '',
                    orderId: ''
                },
                rules: {
                    refuseRemark: [
                        { required: true, message: this.$t('verify.plsInput') }
                    ]
                }
            },
        }
    },
    methods: {
        init(){
            this.returnReasonDialog={
                isVisible: false,
                form: {
                    refuseRemark: '',
                    orderId: ''
                },
                rules: {
                    refuseRemark: [
                        { required: true, message: this.$t('verify.plsInput') }
                    ]
                }
            }},
        cancel(){
            this.init()
        },
        showReunder(info) {
            this.init();
            this.returnReasonDialog.form.orderId = info.orderId;
            this.returnReasonDialog.isVisible = true
        },
        returnHandler() {
            this.$refs['returnReasonDialog.form'].validate(val => {
                if (val) {
                    // row.isDisabledReturn = true;
                    const form = this.returnReasonDialog.form;
                    const params = {
                        orderId: form.orderId,
                        refuseRemark: form.refuseRemark
                    };
                    this.$api.finance.loan.backOrder(params).then(res => {
                        // row.isDisabledReturn = false;
                        const { status, error, msg } = res;
                        if ('1' === status && '00000000' === error) {
                            this.$emit('ReunderSuc')
                            this.returnReasonDialog.isVisible = false;
                            this.$message.success(this.$t('common.successfulOperation'));
                        }
                        else if ('1' === status && '00000000' !== error) {
                            this.$message.error(msg || this.$t('common.failedOperation'));
                        }
                    });
                }
            });
        },
    }
}
</script>